/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.service.utils;

import com.microtripit.mandrillapp.lutung.MandrillApi;
import com.microtripit.mandrillapp.lutung.model.MandrillApiError;
import com.microtripit.mandrillapp.lutung.view.MandrillMessage;
import com.microtripit.mandrillapp.lutung.view.MandrillMessageStatus;
import java.util.ArrayList;

/**
 *
 * @author ECH
 */
public class MandrillClient {
    
    private static final String APIKey = "3U6YqcGWVFY6_YbyK1_F2A";
    
    public void sendEmail(String fromEmail, String fromName, String toEmail, String subject, String body) {
        try {
            MandrillApi mandrillApi = new MandrillApi(APIKey);            
            MandrillMessage message = new MandrillMessage();

            message.setSubject(subject);                
            message.setHtml(body);

            message.setAutoText(true);
            message.setFromEmail(fromEmail);
            message.setFromName(fromName);

            ArrayList<MandrillMessage.Recipient> recipients = new ArrayList<MandrillMessage.Recipient>();
            MandrillMessage.Recipient recipient = new MandrillMessage.Recipient();
            recipient.setEmail(toEmail);
            recipients.add(recipient);

            message.setTo(recipients);
            message.setPreserveRecipients(true);
            
            ArrayList<String> tags = new ArrayList<String>();
            tags.add("rentpad");
            message.setTags(tags);

            MandrillMessageStatus[] messageStatusReports = mandrillApi.messages().send(message, false);
        } 
        catch (MandrillApiError ex) {
            ex.printStackTrace();
        }
        catch (Exception ex) {
            
        }        
    }
        
    public void sendEmail(String fromEmail, String fromName, String toEmail, String subject, String body, String bccEmail) {
        try {
            MandrillApi mandrillApi = new MandrillApi(APIKey);            
            MandrillMessage message = new MandrillMessage();

            message.setSubject(subject);                
            message.setHtml(body);

            message.setAutoText(true);
            message.setFromEmail(fromEmail);
            message.setFromName(fromName);
            //message.setBcc(bccEmail);

            ArrayList<MandrillMessage.Recipient> recipients = new ArrayList<MandrillMessage.Recipient>();
            MandrillMessage.Recipient recipient = new MandrillMessage.Recipient();
            recipient.setEmail(toEmail);
            recipients.add(recipient);

            message.setTo(recipients);
            message.setPreserveRecipients(true);
            
            ArrayList<String> tags = new ArrayList<String>();
            tags.add("rentpad");
            message.setTags(tags);

            MandrillMessageStatus[] messageStatusReports = mandrillApi.messages().send(message, false);
        } 
        catch (MandrillApiError ex) {
            ex.printStackTrace();
        }
        catch (Exception ex) {
            
        }        
    }
    
    public static void main (String [] args) {
        MailjetClient mc = new MailjetClient();
        mc.sendEmail("jess@rentpad.me", "Jessica Garcia", "chux18@gmail.com", "Yeaheh Subject", "inner text");
    }
    
}
